package com.dream.service.recommender.splitter.strage.impl;

import com.dream.service.recommender.domain.enums.UserType;
import com.dream.service.recommender.domain.splitter.SplitterRequest;
import com.dream.service.recommender.toolkits.utils.MurmurHash;

/**
 * Created by zhiji on 2016/3/15.
 * 按照uuid/或者pin分流
 */
public class UserStrategy extends BaseStrategy {

    private UserType userType;

    public UserStrategy(UserType userType) {
        setUserType(userType);
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    @Override
    public int getSeed(SplitterRequest splitterRequest) {
        String source = null;
        if (UserType.UUID == userType) {
            source = splitterRequest.getUuid();
        } else if (UserType.PIN == userType) {
            source = splitterRequest.getPin();
        } else if (UserType.DEVICEID == userType) {
            source = splitterRequest.getDevice_id();
        }
        return (int) Math.abs(MurmurHash.hash(source) % maxtraffic);
    }
}
